package com.mpolicy.dbfile.system.controller;

import com.mpolicy.dbfile.system.domain.ExportCondition;
import com.mpolicy.dbfile.system.service.ITableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/table")
@Api(tags = "系统管理-数据库表管理")
public class TableController{

    @Autowired
    ITableService tableService;

    @GetMapping(value = "/toWord", produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8", name = "导出数据库表信息生成Word")
    @ApiOperation(value = "导出数据库表信息生成Word", httpMethod = "GET", notes = "导出数据库表信息生成Word")
    public void tableToWord(@RequestParam(required = false) String tableName) {
        try {
            tableService.getTableInfo(tableName);
        } catch (Exception e) {
            log.error("导出数据库表信息生成Word失败", e);
        }
    }

    @PostMapping(value = "/toWord/custom", produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8", name = "导出数据库表信息生成Word")
    @ApiOperation(value = "导出自定义数据库表信息生成Word", httpMethod = "POST", notes = "导出数据库表信息生成Word")
    public void tableToWordAllPost(@RequestBody ExportCondition condition) {
        try {
            tableService.getTableInfoWithCustomDb(condition);
        } catch (Exception e) {
            log.error("导出数据库表信息生成Word失败", e);
            e.printStackTrace();
        }
    }
}
